/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.googlecode.jsimplemarket.wicket.pages;

import com.googlecode.jsimplemarket.model.AbstractNomenclator;
import com.googlecode.jsimplemarket.wicket.components.grid.ActionButton;
import com.googlecode.jsimplemarket.wicket.components.grid.ActionButtons;
import com.googlecode.jsimplemarket.wicket.components.grid.ColumnModel;
import com.googlecode.jsimplemarket.wicket.components.grid.DefaultGridAction;
import com.googlecode.jsimplemarket.wicket.components.grid.Grid;
import com.googlecode.jsimplemarket.wicket.components.grid.PageParameters;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import org.apache.wicket.spring.injection.annot.SpringBean;

/**
 *
 * @author Alexandru.Codescu
 */
public class NomenclatorViewPage<T extends AbstractNomenclator> extends DefaultViewPage {
    @SpringBean(name = "defaultGridAction")
    private DefaultGridAction<T> gridAction;
    
    public NomenclatorViewPage(Class<T> clazz) {
        init(clazz, new ActionButton(new PageParameters(NomenclatorEditPage.class, clazz)));
    }
    
    public NomenclatorViewPage(Class<T> clazz, Class<? extends DefaultEditPage> pageClazz, Object... constructorParameters) {
        init(clazz, new ActionButton(new PageParameters(pageClazz, constructorParameters)));
    }
    
    private void init(Class<T> clazz, ActionButton actionButton) {
        ColumnModel[] grids = {
            new ColumnModel("Cod", "cod", String.class),
            new ColumnModel("Denumire", "denumire", String.class),
            new ColumnModel("Data inceput", "dataInceput", Date.class),
            new ColumnModel("Data sfarsit", "dataSfarsit", Date.class)
        };
        List<ColumnModel> columns = Arrays.asList(grids);
        
        ActionButtons actionButtons = new ActionButtons(actionButton);
        Grid<T> dataGrid = new Grid<T>("grid", columns, clazz, gridAction, actionButtons);
        add(dataGrid);
    }
}
